package simple.form.controller.interceptor;

import org.apache.log4j.Logger;
import simple.form.controller.Request;
import simple.form.controller.Response;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 请求日志拦截器(默认)
 * Created by Administrator on 2017/2/24.
 */
public class RequestLogInterceptor extends Interceptor<String>{

    public static Logger log4j = Logger.getLogger(RequestLogInterceptor.class);
    @Override
    public String before(Object controller,Request request,Response response) {
        String requestParam = request.getParamString();
        log4j.info(String.format(controller.getClass().getName() + " request param %s", requestParam));
        return null;
    }

    @Override
    public String after(Object controller,Request request,Response response) {
        String responseContent = response.getResponseResult();
        log4j.info(String.format(controller.getClass().getName() + " response [%s]", responseContent));
        return responseContent;
    }
}
